
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>2.3.4 生成日志: JsonMock · 大数据 数仓实时 课堂笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content=" 李振超">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-prism/prism-solarizedlight.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-change_girls/girls.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi.html" />
    
    
    <link rel="prev" href="234-ri-zhi-fa-song-gong-ju-7c7b3a-loguploader.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://www.atguigu.com/" target="_blank" class="custom-link">联系我们</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">第 1 部分: 日活</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    第  1 章 需求概述
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="../../11-li-xian-chu-li-jia-gou.html">
            
                <a href="../../11-li-xian-chu-li-jia-gou.html">
            
                    
                    1.1 离线处理架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2" data-path="../../12-shi-shi-chu-li-jia-gou.html">
            
                <a href="../../12-shi-shi-chu-li-jia-gou.html">
            
                    
                    1.2 实时处理架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3" data-path="../../13-xu-qiu.html">
            
                <a href="../../13-xu-qiu.html">
            
                    
                    1.3 需求
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../chapter1.html">
            
                <a href="../../chapter1.html">
            
                    
                    第 2 章 模拟数据
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../21-chuang-jian-fu-gong-cheng.html">
            
                <a href="../21-chuang-jian-fu-gong-cheng.html">
            
                    
                    2.1 创建父工程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../22-chuang-jian-common-zi-mo-kuai.html">
            
                <a href="../22-chuang-jian-common-zi-mo-kuai.html">
            
                    
                    2.2 创建 common 子模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../23-chuang-jian-mock-zi-mo-kuai.html">
            
                <a href="../23-chuang-jian-mock-zi-mo-kuai.html">
            
                    
                    2.3 创建 mock 子模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.3.1" data-path="231-chuang-jian-gong-ju-7c7b3a-randomnumutil.html">
            
                <a href="231-chuang-jian-gong-ju-7c7b3a-randomnumutil.html">
            
                    
                    2.3.1 工具类: RandomNumUtil
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.2" data-path="231-chuang-jian-gong-ju-7c7b3a-randomdate.html">
            
                <a href="231-chuang-jian-gong-ju-7c7b3a-randomdate.html">
            
                    
                    2.3.2 工具类: RandomDate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.3" data-path="233-chuang-jian-gong-ju-7c7b3a-radomoptions.html">
            
                <a href="233-chuang-jian-gong-ju-7c7b3a-radomoptions.html">
            
                    
                    2.3.3 工具类: RadomOptions
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.4" data-path="234-ri-zhi-fa-song-gong-ju-7c7b3a-loguploader.html">
            
                <a href="234-ri-zhi-fa-song-gong-ju-7c7b3a-loguploader.html">
            
                    
                    2.3.4 日志发送工具类: LogUploader
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.3.5" data-path="234-sheng-cheng-ri-5fd73a-jsonmock.html">
            
                <a href="234-sheng-cheng-ri-5fd73a-jsonmock.html">
            
                    
                    2.3.4 生成日志: JsonMock
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi.html">
            
                <a href="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi.html">
            
                    
                    第 3 章 启动数据采集服务器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/31-spring-boot-jian-jie.html">
            
                <a href="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/31-spring-boot-jian-jie.html">
            
                    
                    3.1 Spring boot 简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/32-kuai-su-da-jian-spring-boot.html">
            
                <a href="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/32-kuai-su-da-jian-spring-boot.html">
            
                    
                    3.2 快速搭建 Spring boot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/33-chuang-jian-controller.html">
            
                <a href="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/33-chuang-jian-controller.html">
            
                    
                    3.3 创建 Controller
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/34-bu-shu-dao-linux-fu-wu-qi.html">
            
                <a href="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/34-bu-shu-dao-linux-fu-wu-qi.html">
            
                    
                    3.4 部署到 Linux 服务器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../di-4-zhang-shi-yong-nginx-fu-zai-jun-heng.html">
            
                <a href="../../di-4-zhang-shi-yong-nginx-fu-zai-jun-heng.html">
            
                    
                    第 4 章 使用 Nginx 负载均衡
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../../di-4-zhang-shi-yong-nginx-fu-zai-jun-heng/41-nginx-jian-jie.html">
            
                <a href="../../di-4-zhang-shi-yong-nginx-fu-zai-jun-heng/41-nginx-jian-jie.html">
            
                    
                    4.1 Nginx 简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../../di-4-zhang-shi-yong-nginx-fu-zai-jun-heng/42-nginx-an-zhuang.html">
            
                <a href="../../di-4-zhang-shi-yong-nginx-fu-zai-jun-heng/42-nginx-an-zhuang.html">
            
                    
                    4.2 Nginx 安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../../di-4-zhang-shi-yong-nginx-fu-zai-jun-heng/43-pei-zhi-fu-zai-jun-heng.html">
            
                <a href="../../di-4-zhang-shi-yong-nginx-fu-zai-jun-heng/43-pei-zhi-fu-zai-jun-heng.html">
            
                    
                    4.3  配置负载均衡
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../di-5-zhang-shi-yong-sparkstreaming-da-jian-shi-shi-chu-li-mo-kuai.html">
            
                <a href="../../di-5-zhang-shi-yong-sparkstreaming-da-jian-shi-shi-chu-li-mo-kuai.html">
            
                    
                    第 5 章 使用 Spark Streaming 搭建实时处理模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../../di-5-zhang-shi-yong-sparkstreaming-da-jian-shi-shi-chu-li-mo-kuai/51-chuang-jian-shi-xian-chu-li-mo-kuai.html">
            
                <a href="../../di-5-zhang-shi-yong-sparkstreaming-da-jian-shi-shi-chu-li-mo-kuai/51-chuang-jian-shi-xian-chu-li-mo-kuai.html">
            
                    
                    5.1 创建实现处理模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../di-5-zhang-shi-yong-sparkstreaming-da-jian-shi-shi-chu-li-mo-kuai/52-cong-kafka-du-qu-shu-ju.html">
            
                <a href="../../di-5-zhang-shi-yong-sparkstreaming-da-jian-shi-shi-chu-li-mo-kuai/52-cong-kafka-du-qu-shu-ju.html">
            
                    
                    5.2 从 Kafka 读取数据并保持到 Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../../di-5-zhang-shi-yong-sparkstreaming-da-jian-shi-shi-chu-li-mo-kuai/53-dui-shu-ju-jin-xing-qing-xi-he-guo-lv.html">
            
                <a href="../../di-5-zhang-shi-yong-sparkstreaming-da-jian-shi-shi-chu-li-mo-kuai/53-dui-shu-ju-jin-xing-qing-xi-he-guo-lv.html">
            
                    
                    5.3 对数据进行清洗和过滤
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../../di-6-zhang-shu-ju-xieru-dao-elasticsearch.html">
            
                <a href="../../di-6-zhang-shu-ju-xieru-dao-elasticsearch.html">
            
                    
                    第 6 章 数据写入到 ElasticSearch
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../di-6-zhang-shu-ju-xieru-dao-elasticsearch/61-elasticsearch-de-ji-ben-gai-nian-hui-gu.html">
            
                <a href="../../di-6-zhang-shu-ju-xieru-dao-elasticsearch/61-elasticsearch-de-ji-ben-gai-nian-hui-gu.html">
            
                    
                    6.1 ElasticSearch 的基本概念回顾
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../../di-6-zhang-shu-ju-xieru-dao-elasticsearch/62-she-ji-es-suo-yin-jie-gou.html">
            
                <a href="../../di-6-zhang-shu-ju-xieru-dao-elasticsearch/62-she-ji-es-suo-yin-jie-gou.html">
            
                    
                    6.2 设计 ES 索引结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../../di-6-zhang-shu-ju-xieru-dao-elasticsearch/63-chuang-jian-cao-zuo-es-de-gong-ju-lei.html">
            
                <a href="../../di-6-zhang-shu-ju-xieru-dao-elasticsearch/63-chuang-jian-cao-zuo-es-de-gong-ju-lei.html">
            
                    
                    6.3 创建操作 ES 的工具类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../../di-6-zhang-shu-ju-xieru-dao-elasticsearch/64-ba-yong-hu-startup-xin-xi-xie-ru-dao-es.html">
            
                <a href="../../di-6-zhang-shu-ju-xieru-dao-elasticsearch/64-ba-yong-hu-startup-xin-xi-xie-ru-dao-es.html">
            
                    
                    6.4 把用户 Startup  信息写入到 ES
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../../di-7-zhang-ti-gong-cha-xun-ri-huo-he-xiao-shi-ming-xi-de-jie-kou.html">
            
                <a href="../../di-7-zhang-ti-gong-cha-xun-ri-huo-he-xiao-shi-ming-xi-de-jie-kou.html">
            
                    
                    第 7 章 提供查询日活和小时明细的接口
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../../di-7-zhang-ti-gong-cha-xun-ri-huo-he-xiao-shi-ming-xi-de-jie-kou/71-shi-yong-kibana-cha-xun-ri-huo-he-xiao-shi-ming-xi.html">
            
                <a href="../../di-7-zhang-ti-gong-cha-xun-ri-huo-he-xiao-shi-ming-xi-de-jie-kou/71-shi-yong-kibana-cha-xun-ri-huo-he-xiao-shi-ming-xi.html">
            
                    
                    7.1 使用 Kibana 查询日活和小时明细
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../../di-7-zhang-ti-gong-cha-xun-ri-huo-he-xiao-shi-ming-xi-de-jie-kou/72-chuang-jian-spring-boot-zi-mo-kuai-lai-ti-gong-dui-wai-cha-xun-jie-kou.html">
            
                <a href="../../di-7-zhang-ti-gong-cha-xun-ri-huo-he-xiao-shi-ming-xi-de-jie-kou/72-chuang-jian-spring-boot-zi-mo-kuai-lai-ti-gong-dui-wai-cha-xun-jie-kou.html">
            
                    
                    7.2 创建 Spring boot 子模块来提供对外查询接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../../di-7-zhang-ti-gong-cha-xun-ri-huo-he-xiao-shi-ming-xi-de-jie-kou/73-shi-yong-serviceceng-lai-cong-es-du-qu-shu-ju.html">
            
                <a href="../../di-7-zhang-ti-gong-cha-xun-ri-huo-he-xiao-shi-ming-xi-de-jie-kou/73-shi-yong-serviceceng-lai-cong-es-du-qu-shu-ju.html">
            
                    
                    7.3 使用 service 层来从 es 读取数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../../di-7-zhang-ti-gong-cha-xun-ri-huo-he-xiao-shi-ming-xi-de-jie-kou/74-ding-yi-controller-lai-jie-shou-yong-hu-qing-qiu.html">
            
                <a href="../../di-7-zhang-ti-gong-cha-xun-ri-huo-he-xiao-shi-ming-xi-de-jie-kou/74-ding-yi-controller-lai-jie-shou-yong-hu-qing-qiu.html">
            
                    
                    7.4 定义 Controller 来接收用户请求
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../../di-8-zhang-ke-shi-hua-zhan-shi.html">
            
                <a href="../../di-8-zhang-ke-shi-hua-zhan-shi.html">
            
                    
                    第 8 章 可视化展示
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第 2 部分 业务数据处理</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../../di-9-zhang-canal-de-shi-yong.html">
            
                <a href="../../di-9-zhang-canal-de-shi-yong.html">
            
                    
                    第 9 章 使用 Canal
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../../di-9-zhang-canal-de-shi-yong/91-wei-shi-yao-xu-yao-canal.html">
            
                <a href="../../di-9-zhang-canal-de-shi-yong/91-wei-shi-yao-xu-yao-canal.html">
            
                    
                    9.1 为什么需要 Canal
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../../di-9-zhang-canal-de-shi-yong/92-canal-gong-zuo-yuan-li.html">
            
                <a href="../../di-9-zhang-canal-de-shi-yong/92-canal-gong-zuo-yuan-li.html">
            
                    
                    9.2 Canal 工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../../di-9-zhang-canal-de-shi-yong/93-pei-zhi-mysql.html">
            
                <a href="../../di-9-zhang-canal-de-shi-yong/93-pei-zhi-mysql.html">
            
                    
                    9.3 配置 Mysql
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../../di-9-zhang-canal-de-shi-yong/94-zhun-bei-shu-ju-ku-shu-ju.html">
            
                <a href="../../di-9-zhang-canal-de-shi-yong/94-zhun-bei-shu-ju-ku-shu-ju.html">
            
                    
                    9.4 准备数据库数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="../../di-9-zhang-canal-de-shi-yong/95-an-zhuang-canal.html">
            
                <a href="../../di-9-zhang-canal-de-shi-yong/95-an-zhuang-canal.html">
            
                    
                    9.5 安装 canal 和启动
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../../di-10-zhang-mei-ri-ding-dan-liang.html">
            
                <a href="../../di-10-zhang-mei-ri-ding-dan-liang.html">
            
                    
                    第 10 章 从 Canal 读取数据到 Kafka
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../../di-10-zhang-mei-ri-ding-dan-liang/101-cong-canal-du-qu-shu-ju.html">
            
                <a href="../../di-10-zhang-mei-ri-ding-dan-liang/101-cong-canal-du-qu-shu-ju.html">
            
                    
                    10.1 从 Canal 读取数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="../../di-10-zhang-mei-ri-ding-dan-liang/102-du-qu-de-shu-ju-fa-song-dao-kafka.html">
            
                <a href="../../di-10-zhang-mei-ri-ding-dan-liang/102-du-qu-de-shu-ju-fa-song-dao-kafka.html">
            
                    
                    10.2 读取的数据发送到 Kafka
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../../di-11-zhang-cong-kafka-du-qu-ding-dan-shu-ju-bing-xie-ru-dao-es.html">
            
                <a href="../../di-11-zhang-cong-kafka-du-qu-ding-dan-shu-ju-bing-xie-ru-dao-es.html">
            
                    
                    第 11 章 从 Kafka 读取订单数据并写入到 ES
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../../di-11-zhang-cong-kafka-du-qu-ding-dan-shu-ju-bing-xie-ru-dao-es/111-cong-kafka-du-qu-shu-ju.html">
            
                <a href="../../di-11-zhang-cong-kafka-du-qu-ding-dan-shu-ju-bing-xie-ru-dao-es/111-cong-kafka-du-qu-shu-ju.html">
            
                    
                    11.1 从 Kafka 读取数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../../di-11-zhang-cong-kafka-du-qu-ding-dan-shu-ju-bing-xie-ru-dao-es/112-xie-ru-shu-ju-dao-es.html">
            
                <a href="../../di-11-zhang-cong-kafka-du-qu-ding-dan-shu-ju-bing-xie-ru-dao-es/112-xie-ru-shu-ju-dao-es.html">
            
                    
                    11.2 写入数据到 ES
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../../di-12-zhang-fa-bu-shu-ju.html">
            
                <a href="../../di-12-zhang-fa-bu-shu-ju.html">
            
                    
                    第 12 章 发布数据
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../../di-12-zhang-fa-bu-shu-ju/121-dsl-yu-ju.html">
            
                <a href="../../di-12-zhang-fa-bu-shu-ju/121-dsl-yu-ju.html">
            
                    
                    12.1 查询 DSL 语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../../di-12-zhang-fa-bu-shu-ju/122-kai-fa-dui-wai-jie-kou.html">
            
                <a href="../../di-12-zhang-fa-bu-shu-ju/122-kai-fa-dui-wai-jie-kou.html">
            
                    
                    12.2 开发对外接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../../di-12-zhang-fa-bu-shu-ju/123-tu-xing-hua-zhan-shi.html">
            
                <a href="../../di-12-zhang-fa-bu-shu-ju/123-tu-xing-hua-zhan-shi.html">
            
                    
                    12.3 图形化展示
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">第 3 部分 灵活查询</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei.html">
            
                    
                    第 13 章 灵活查询用户的购买行为
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei/131-si-lu-fen-xi.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei/131-si-lu-fen-xi.html">
            
                    
                    13.1 思路分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei/132-t+1-ye-wu-shu-ju-de-shu-ju-liu-cheng.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei/132-t+1-ye-wu-shu-ju-de-shu-ju-liu-cheng.html">
            
                    
                    13.2 T+1 业务数据的数据流程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.2.1" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei/132-t+1-ye-wu-shu-ju-de-shu-ju-liu-cheng/1321-zhun-bei-ods-ceng.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei/132-t+1-ye-wu-shu-ju-de-shu-ju-liu-cheng/1321-zhun-bei-ods-ceng.html">
            
                    
                    13.2.1 准备 ODS 层
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2.2" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei/132-t+1-ye-wu-shu-ju-de-shu-ju-liu-cheng/1322-zhun-bei-dwd-ceng.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei/132-t+1-ye-wu-shu-ju-de-shu-ju-liu-cheng/1322-zhun-bei-dwd-ceng.html">
            
                    
                    13.2.2 准备 DWD 层
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2.3" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei/132-t+1-ye-wu-shu-ju-de-shu-ju-liu-cheng/1323-zhun-bei-dws-ceng.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-13-zhang-ling-huo-cha-xun-yong-hu-de-gou-mai-xing-wei/132-t+1-ye-wu-shu-ju-de-shu-ju-liu-cheng/1323-zhun-bei-dws-ceng.html">
            
                    
                    13.2.3 准备 DWS 层
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-14-zhang-shu-cang-zhong-shu-ju-dao-ru-dao-es.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-14-zhang-shu-cang-zhong-shu-ju-dao-ru-dao-es.html">
            
                    
                    第 14 章 数仓中数据导入到 ES
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-14-zhang-shu-cang-zhong-shu-ju-dao-ru-dao-es/141-chuang-jian-idea-mo-kuai.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-14-zhang-shu-cang-zhong-shu-ju-dao-ru-dao-es/141-chuang-jian-idea-mo-kuai.html">
            
                    
                    14.1 创建 idea 模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-14-zhang-shu-cang-zhong-shu-ju-dao-ru-dao-es/142-wan-cheng-cong-dw-dao-es-de-ye-wu-dai-ma.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-14-zhang-shu-cang-zhong-shu-ju-dao-ru-dao-es/142-wan-cheng-cong-dw-dao-es-de-ye-wu-dai-ma.html">
            
                    
                    14.2 完成从 dw 到 es 的业务代码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-15-zhang-fa-bu-ling-huo-cha-xun-yong-dao-de-shu-ju.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-15-zhang-fa-bu-ling-huo-cha-xun-yong-dao-de-shu-ju.html">
            
                    
                    第 15 章 发布灵活查询用到的数据
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-15-zhang-fa-bu-ling-huo-cha-xun-yong-dao-de-shu-ju/151-zai-gmall-publish-zi-mo-kuai-zhong-tian-jia-jie-kou.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-15-zhang-fa-bu-ling-huo-cha-xun-yong-dao-de-shu-ju/151-zai-gmall-publish-zi-mo-kuai-zhong-tian-jia-jie-kou.html">
            
                    
                    15.1 在 gmall-publish 子模块中读取 ES 中数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-15-zhang-fa-bu-ling-huo-cha-xun-yong-dao-de-shu-ju/152-zai-controller-zhong-nian-tian-jia-dui-wai-fang-wen-jie-kou.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-15-zhang-fa-bu-ling-huo-cha-xun-yong-dao-de-shu-ju/152-zai-controller-zhong-nian-tian-jia-dui-wai-fang-wen-jie-kou.html">
            
                    
                    15.2 在 Controller 中年添加对外访问接口
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../../di-3-bu-fen-ling-huo-cha-xun/di-16-zhang-ke-shi-hua-zhan-shi.html">
            
                <a href="../../di-3-bu-fen-ling-huo-cha-xun/di-16-zhang-ke-shi-hua-zhan-shi.html">
            
                    
                    第 16 章 可视化展示
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >2.3.4 生成日志: JsonMock</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="234-&#x751F;&#x6210;&#x65E5;&#x5FD7;-jsonmock">2.3.4 &#x751F;&#x6210;&#x65E5;&#x5FD7;: <code>JsonMock</code></h1>
<p>&#x751F;&#x6210;&#x6A21;&#x62DF;&#x6570;&#x636E;</p>
<pre class="language-"><code class="lang-scala"><span class="token keyword">package</span> com<span class="token punctuation">.</span>atguigu<span class="token punctuation">.</span>dw<span class="token punctuation">.</span>gmall<span class="token punctuation">.</span>mock

<span class="token keyword">import</span> java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>Date

<span class="token keyword">import</span> com<span class="token punctuation">.</span>alibaba<span class="token punctuation">.</span>fastjson<span class="token punctuation">.</span><span class="token punctuation">{</span>JSON<span class="token punctuation">,</span> JSONObject<span class="token punctuation">}</span>
<span class="token keyword">import</span> com<span class="token punctuation">.</span>atguigu<span class="token punctuation">.</span>dw<span class="token punctuation">.</span>gmall<span class="token punctuation">.</span>mock<span class="token punctuation">.</span>util<span class="token punctuation">.</span><span class="token punctuation">{</span>LogUploader<span class="token punctuation">,</span> RandomNumUtil<span class="token punctuation">,</span> RandomOptions<span class="token punctuation">}</span>

<span class="token keyword">object</span> JsonMock <span class="token punctuation">{</span>

    <span class="token keyword">val</span> startupNum <span class="token operator">=</span> <span class="token number">100000</span> <span class="token comment">// &#x751F;&#x6210;&#x7684;&#x542F;&#x52A8;&#x65E5;&#x5FD7;&#x7684;&#x8BB0;&#x5F55;&#x6570;</span>
    <span class="token keyword">val</span> eventNum <span class="token operator">=</span> <span class="token number">200000</span> <span class="token comment">// &#x751F;&#x6210;&#x7684;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;&#x7684;&#x8BB0;&#x5F55;&#x6570;</span>

    <span class="token comment">// &#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;&#x5206;&#x5E03;</span>
    <span class="token keyword">val</span> osOpts <span class="token operator">=</span> RandomOptions<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&quot;ios&quot;</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;android&quot;</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token comment">// &#x65E5;&#x5FD7;&#x5F00;&#x59CB;&#x65F6;&#x95F4;</span>
    <span class="token keyword">var</span> startDate<span class="token operator">:</span> Date <span class="token operator">=</span> _
    <span class="token comment">// &#x65E5;&#x5FD7;&#x7ED3;&#x675F;&#x65F6;&#x95F4;</span>
    <span class="token keyword">var</span> endDate<span class="token operator">:</span> Date <span class="token operator">=</span> _

    <span class="token comment">// &#x5730;&#x7406;&#x4F4D;&#x7F6E;&#x5206;&#x5E03;</span>
    <span class="token keyword">val</span> areaOpts <span class="token operator">=</span> RandomOptions<span class="token punctuation">(</span>
        <span class="token punctuation">(</span><span class="token string">&quot;beijing&quot;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;shanghai&quot;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;guangdong&quot;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">(</span><span class="token string">&quot;hebei&quot;</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;heilongjiang&quot;</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;shandong&quot;</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">(</span><span class="token string">&quot;tianjin&quot;</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;guizhou&quot;</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;shangxi&quot;</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">(</span><span class="token string">&quot;sichuan&quot;</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;xinjiang&quot;</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span>
    <span class="token punctuation">)</span>

    <span class="token comment">// appId</span>
    <span class="token keyword">val</span> appId <span class="token operator">=</span> <span class="token string">&quot;gmall&quot;</span>

    <span class="token comment">// app &#x7684;&#x7248;&#x672C;&#x5206;&#x5E03;</span>
    <span class="token keyword">val</span> versionOpts <span class="token operator">=</span> RandomOptions<span class="token punctuation">(</span>
        <span class="token punctuation">(</span><span class="token string">&quot;1.2.0&quot;</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;1.1.2&quot;</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">(</span><span class="token string">&quot;1.1.3&quot;</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;1.1.1&quot;</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token comment">// &#x7528;&#x6237;&#x884C;&#x4E3A;&#x7684;&#x5206;&#x5E03;(&#x4E8B;&#x4EF6;&#x5206;&#x5E03;)</span>
    <span class="token keyword">val</span> eventOpts <span class="token operator">=</span> RandomOptions<span class="token punctuation">(</span>
        <span class="token punctuation">(</span><span class="token string">&quot;addFavor&quot;</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;addComment&quot;</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">(</span><span class="token string">&quot;addCart&quot;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;clickItem&quot;</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token comment">// app &#x5206;&#x53D1;&#x6E20;&#x9053;&#x5206;&#x5E03;</span>
    <span class="token keyword">val</span> channelOpts <span class="token operator">=</span> RandomOptions<span class="token punctuation">(</span>
        <span class="token punctuation">(</span><span class="token string">&quot;xiaomi&quot;</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;huawei&quot;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;wandoujia&quot;</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">(</span><span class="token string">&quot;360&quot;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;tencent&quot;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;baidu&quot;</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;website&quot;</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token comment">// &#x751F;&#x6210;&#x6A21;&#x62DF;&#x6570;&#x636E;&#x7684;&#x65F6;&#x5019;&#x662F;&#x5426;&#x7ED3;&#x675F;&#x9000;&#x51FA;</span>
    <span class="token keyword">val</span> quitOpts <span class="token operator">=</span> RandomOptions<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">95</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token comment">// &#x6A21;&#x62DF;&#x51FA;&#x6765;&#x4E00;&#x6761;&#x542F;&#x52A8;&#x65E5;&#x5FD7;</span>
    <span class="token keyword">def</span> initOneStartupLog<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">String</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
        <span class="token comment">/*
        `type` string   COMMENT &apos;&#x65E5;&#x5FD7;&#x7C7B;&#x578B;&apos;,
        `mid` string COMMENT &apos;&#x8BBE;&#x5907;&#x552F;&#x4E00;&#x6807;&#x8BC6;&apos;,
        `uid` string COMMENT &apos;&#x7528;&#x6237;&#x6807;&#x8BC6;&apos;,
        `os` string COMMENT &apos;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&apos;, ,
        `appId` string COMMENT &apos;&#x5E94;&#x7528;id&apos;, ,
        `version` string COMMENT &apos;&#x7248;&#x672C;&#x53F7;&apos;,
        `ts` bigint COMMENT &apos;&#x542F;&#x52A8;&#x65F6;&#x95F4;&apos;,    &#x8003;&#x8651;&#x6BCF;&#x4E2A;&#x7EC8;&#x7AEF;&#x7684;&#x65F6;&#x95F4;&#x7684;&#x4E0D;&#x51C6;&#x7FA4;&#x6027;, &#x65F6;&#x95F4;&#x662F;&#x5C06;&#x6765;&#x5728;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x6765;&#x751F;&#x6210;
        `area` string COMMENT &apos;&#x57CE;&#x5E02;&apos;
        `channel` string COMMENT &apos;&#x6E20;&#x9053;&apos;
         */</span>
        <span class="token keyword">val</span> mid<span class="token operator">:</span> <span class="token builtin">String</span> <span class="token operator">=</span> <span class="token string">&quot;mid_&quot;</span> <span class="token operator">+</span> RandomNumUtil<span class="token punctuation">.</span>randomInt<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">500</span><span class="token punctuation">)</span>
        <span class="token keyword">val</span> uid<span class="token operator">:</span> <span class="token builtin">String</span> <span class="token operator">=</span> <span class="token string">&quot;&quot;</span> <span class="token operator">+</span> RandomNumUtil<span class="token punctuation">.</span>randomInt<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">10000</span><span class="token punctuation">)</span>
        <span class="token keyword">val</span> os<span class="token operator">:</span> <span class="token builtin">String</span> <span class="token operator">=</span> osOpts<span class="token punctuation">.</span>getRandomOption<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">val</span> appId<span class="token operator">:</span> <span class="token builtin">String</span> <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>appId
        <span class="token keyword">val</span> area<span class="token operator">:</span> <span class="token builtin">String</span> <span class="token operator">=</span> areaOpts<span class="token punctuation">.</span>getRandomOption<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">val</span> version<span class="token operator">:</span> <span class="token builtin">String</span> <span class="token operator">=</span> versionOpts<span class="token punctuation">.</span>getRandomOption<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">val</span> channel<span class="token operator">:</span> <span class="token builtin">String</span> <span class="token operator">=</span> channelOpts<span class="token punctuation">.</span>getRandomOption<span class="token punctuation">(</span><span class="token punctuation">)</span>

        <span class="token keyword">val</span> obj <span class="token operator">=</span> <span class="token keyword">new</span> JSONObject<span class="token punctuation">(</span><span class="token punctuation">)</span>
        obj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;type&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;startup&quot;</span><span class="token punctuation">)</span>
        obj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;mid&quot;</span><span class="token punctuation">,</span> mid<span class="token punctuation">)</span>
        obj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;uid&quot;</span><span class="token punctuation">,</span> uid<span class="token punctuation">)</span>
        obj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;os&quot;</span><span class="token punctuation">,</span> os<span class="token punctuation">)</span>
        obj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;appId&quot;</span><span class="token punctuation">,</span> appId<span class="token punctuation">)</span>
        obj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;area&quot;</span><span class="token punctuation">,</span> area<span class="token punctuation">)</span>
        obj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;channel&quot;</span><span class="token punctuation">,</span> channel<span class="token punctuation">)</span>
        obj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;version&quot;</span><span class="token punctuation">,</span> version<span class="token punctuation">)</span>
        <span class="token comment">// &#x8FD4;&#x56DE; json &#x683C;&#x5F0F;&#x5B57;&#x7B26;&#x4E32;</span>
        obj<span class="token punctuation">.</span>toJSONString
    <span class="token punctuation">}</span>

    <span class="token comment">// &#x6A21;&#x62DF;&#x51FA;&#x6765;&#x4E00;&#x6761;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;  &#x53C2;&#x6570;: json &#x683C;&#x5F0F;&#x7684;&#x542F;&#x52A8;&#x65E5;&#x5FD7;</span>
    <span class="token keyword">def</span> initOneEventLog<span class="token punctuation">(</span>startupLogJson<span class="token operator">:</span> <span class="token builtin">String</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
        <span class="token comment">/*`
        type` string   COMMENT &apos;&#x65E5;&#x5FD7;&#x7C7B;&#x578B;&apos;,
        `mid` string COMMENT &apos;&#x8BBE;&#x5907;&#x552F;&#x4E00;&#x6807;&#x8BC6;&apos;,
        `uid` string COMMENT &apos;&#x7528;&#x6237;&#x6807;&#x8BC6;&apos;,
        `os` string COMMENT &apos;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&apos;,
        `appId` string COMMENT &apos;&#x5E94;&#x7528;id&apos;,
        `area` string COMMENT &apos;&#x5730;&#x533A;&apos; ,
        `eventId` string COMMENT &apos;&#x4E8B;&#x4EF6;id&apos;,
        `pageId` string COMMENT &apos;&#x5F53;&#x524D;&#x9875;&apos;,
        `nextPageId` string COMMENT &apos;&#x8DF3;&#x8F6C;&#x9875;&apos;,
        `itemId` string COMMENT &apos;&#x5546;&#x54C1;&#x7F16;&#x53F7;&apos;,
        `ts` bigint COMMENT &apos;&#x65F6;&#x95F4;&apos;
         */</span>
        <span class="token keyword">val</span> startupLogObj<span class="token operator">:</span> JSONObject <span class="token operator">=</span> JSON<span class="token punctuation">.</span>parseObject<span class="token punctuation">(</span>startupLogJson<span class="token punctuation">)</span>

        <span class="token keyword">val</span> eventLogObj <span class="token operator">=</span> <span class="token keyword">new</span> JSONObject<span class="token punctuation">(</span><span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;type&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;event&quot;</span><span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;mid&quot;</span><span class="token punctuation">,</span> startupLogObj<span class="token punctuation">.</span>getString<span class="token punctuation">(</span><span class="token string">&quot;mid&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;uid&quot;</span><span class="token punctuation">,</span> startupLogObj<span class="token punctuation">.</span>getString<span class="token punctuation">(</span><span class="token string">&quot;uid&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;os&quot;</span><span class="token punctuation">,</span> startupLogObj<span class="token punctuation">.</span>getString<span class="token punctuation">(</span><span class="token string">&quot;os&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;appId&quot;</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>appId<span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;area&quot;</span><span class="token punctuation">,</span> startupLogObj<span class="token punctuation">.</span>getString<span class="token punctuation">(</span><span class="token string">&quot;area&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;eventId&quot;</span><span class="token punctuation">,</span> eventOpts<span class="token punctuation">.</span>getRandomOption<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;pageId&quot;</span><span class="token punctuation">,</span> RandomNumUtil<span class="token punctuation">.</span>randomInt<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;nextPageId&quot;</span><span class="token punctuation">,</span> RandomNumUtil<span class="token punctuation">.</span>randomInt<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string">&quot;itemId&quot;</span><span class="token punctuation">,</span> RandomNumUtil<span class="token punctuation">.</span>randomInt<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        eventLogObj<span class="token punctuation">.</span>toJSONString
    <span class="token punctuation">}</span>

    <span class="token comment">// &#x5F00;&#x59CB;&#x751F;&#x6210;&#x65E5;&#x5FD7;</span>
    <span class="token keyword">def</span> generateLog<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Unit</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
        <span class="token punctuation">(</span><span class="token number">0</span> to startupNum<span class="token punctuation">)</span><span class="token punctuation">.</span>foreach<span class="token punctuation">(</span>_ <span class="token keyword">=&gt;</span> <span class="token punctuation">{</span>
            <span class="token comment">// &#x751F;&#x6210;&#x4E00;&#x6761;&#x542F;&#x52A8;&#x65E5;&#x5FD7;</span>
            <span class="token keyword">val</span> oneStartupLog<span class="token operator">:</span> <span class="token builtin">String</span> <span class="token operator">=</span> initOneStartupLog<span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token comment">// &#x53D1;&#x9001;&#x542F;&#x52A8;&#x65E5;&#x5FD7;</span>
            LogUploader<span class="token punctuation">.</span>sendLog<span class="token punctuation">(</span>oneStartupLog<span class="token punctuation">)</span>
            <span class="token comment">// &#x6A21;&#x62DF;&#x51FA;&#x6765;&#x591A;&#x6761;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;</span>
            <span class="token keyword">while</span> <span class="token punctuation">(</span><span class="token operator">!</span>quitOpts<span class="token punctuation">.</span>getRandomOption<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment">// &#x751F;&#x6210;&#x4E00;&#x6761;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;</span>
                <span class="token keyword">val</span> oneEventLog<span class="token operator">:</span> <span class="token builtin">String</span> <span class="token operator">=</span> initOneEventLog<span class="token punctuation">(</span>oneStartupLog<span class="token punctuation">)</span>
                <span class="token comment">// &#x53D1;&#x9001;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;</span>
                LogUploader<span class="token punctuation">.</span>sendLog<span class="token punctuation">(</span>oneEventLog<span class="token punctuation">)</span>
                Thread<span class="token punctuation">.</span>sleep<span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span>
            <span class="token punctuation">}</span>
            Thread<span class="token punctuation">.</span>sleep<span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">def</span> main<span class="token punctuation">(</span>args<span class="token operator">:</span> Array<span class="token punctuation">[</span><span class="token builtin">String</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Unit</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
        <span class="token comment">// &#x6D4B;&#x8BD5;</span>
        generateLog<span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; &#x5C1A;&#x7845;&#x8C37;&#x5927;&#x6570;&#x636E; 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification"><br>&#x8BE5;&#x6587;&#x4EF6;&#x6700;&#x540E;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2019-06-16 16:02:00
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="234-ri-zhi-fa-song-gong-ju-7c7b3a-loguploader.html" class="navigation navigation-prev " aria-label="Previous page: 2.3.4 日志发送工具类: LogUploader">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../../di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi.html" class="navigation navigation-next " aria-label="Next page: 第 3 章 启动数据采集服务器">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"2.3.4 生成日志: JsonMock","level":"1.2.3.5","depth":3,"next":{"title":"第 3 章 启动数据采集服务器","level":"1.3","depth":1,"path":"di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi.md","ref":"di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi.md","articles":[{"title":"3.1 Spring boot 简介","level":"1.3.1","depth":2,"path":"di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/31-spring-boot-jian-jie.md","ref":"di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/31-spring-boot-jian-jie.md","articles":[]},{"title":"3.2 快速搭建 Spring boot","level":"1.3.2","depth":2,"path":"di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/32-kuai-su-da-jian-spring-boot.md","ref":"di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/32-kuai-su-da-jian-spring-boot.md","articles":[]},{"title":"3.3 创建 Controller","level":"1.3.3","depth":2,"path":"di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/33-chuang-jian-controller.md","ref":"di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/33-chuang-jian-controller.md","articles":[]},{"title":"3.4 部署到 Linux 服务器","level":"1.3.4","depth":2,"path":"di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/34-bu-shu-dao-linux-fu-wu-qi.md","ref":"di-3-zhang-qi-dong-shu-ju-cai-ji-fu-wu-qi/34-bu-shu-dao-linux-fu-wu-qi.md","articles":[]}]},"previous":{"title":"2.3.4 日志发送工具类: LogUploader","level":"1.2.3.4","depth":3,"path":"chapter1/23-chuang-jian-mock-zi-mo-kuai/234-ri-zhi-fa-song-gong-ju-7c7b3a-loguploader.md","ref":"chapter1/23-chuang-jian-mock-zi-mo-kuai/234-ri-zhi-fa-song-gong-ju-7c7b3a-loguploader.md","articles":[]},"dir":"ltr"},"config":{"plugins":["splitter","expandable-chapters-small","page-toc-button","-highlight","prism","prism-themes","tbfed-pagefooter","sitemap","change_girls","livereload"],"styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy 尚硅谷大数据 2019","modify_label":"<br>该文件最后修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-solarizedlight.css"]},"disqus":{"shortName":"zhenchao125"},"livereload":{},"splitter":{},"change_girls":{"time":30,"urls":["http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/62171757.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/83394736.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/15906185.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/15906185.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/3394270.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/65028582.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/20359261.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/37472401.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/3355397.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/11075549.jpg-atguiguImg"]},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"sitemap":{"hostname":"http://bigdataatguigu.applinzi.com/"},"page-toc-button":{"maxTocDepth":3,"minTocSize":2},"prism-themes":{},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":" 李振超","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"大数据 数仓实时 课堂笔记","language":"zh-hans","links":{"sidebar":{"联系我们":"http://www.atguigu.com/"}},"gitbook":"*","description":"课堂笔记,学生提前预习"},"file":{"path":"chapter1/23-chuang-jian-mock-zi-mo-kuai/234-sheng-cheng-ri-5fd73a-jsonmock.md","mtime":"2019-06-16T08:02:00.686Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-07-24T04:24:21.560Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-change_girls/girls.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

